home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / answers / lisp-faq / part1 next >
Encoding:
Text File  |  1993-06-13  |  62.9 KB  |  1,335 lines

  1. Newsgroups: comp.lang.lisp,news.answers,comp.answers
  2. Path: senator-bedfellow.mit.edu!enterpoop.mit.edu!usc!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!bb3.andrew.cmu.edu!crabapple.srv.cs.cmu.edu!mkant
  3. From: mkant+@cs.cmu.edu (Mark Kantrowitz)
  4. Subject: FAQ: Lisp Frequently Asked Questions 1/7 [Monthly posting]
  5. Message-ID: <lisp-faq-1.text_739958414@cs.cmu.edu>
  6. Followup-To: poster
  7. Summary: Introductory Matter and Bibliography of Introductions and References
  8. Sender: news@cs.cmu.edu (Usenet News System)
  9. Supersedes: <lisp-faq-1.text_737280016@cs.cmu.edu>
  10. Nntp-Posting-Host: a.gp.cs.cmu.edu
  11. Reply-To: lisp-faq@think.com
  12. Organization: School of Computer Science, Carnegie Mellon
  13. Date: Sun, 13 Jun 1993 08:00:35 GMT
  14. Approved: news-answers-request@MIT.Edu
  15. Expires: Sun, 25 Jul 1993 08:00:14 GMT
  16. Lines: 1316
  17. Xref: senator-bedfellow.mit.edu comp.lang.lisp:10302 news.answers:9332 comp.answers:967
  18.  
  19. Archive-name: lisp-faq/part1
  20. Last-Modified: Mon Jun  7 18:40:07 1993 by Mark Kantrowitz
  21. Version: 1.34
  22.  
  23. ;;; ****************************************************************
  24. ;;; Answers to Frequently Asked Questions about Lisp ***************
  25. ;;; ****************************************************************
  26. ;;; Written by Mark Kantrowitz and Barry Margolin
  27. ;;; lisp-faq-1.text -- 63777 bytes
  28.  
  29. This post contains Part 1 of the Lisp FAQ.
  30.  
  31. If you think of questions that are appropriate for this FAQ, or would
  32. like to improve an answer, please send email to us at lisp-faq@think.com.
  33.  
  34. Note that the lisp-faq mailing list is for discussion of the content
  35. of the FAQ posting only.  It is not the place to ask questions about Lisp;
  36. use either the common-lisp@ai.sri.com mailing list or the
  37. comp.lang.lisp newsgroup for that.  If a question appears frequently
  38. in one of those forums, it will get added to the FAQ list.
  39.  
  40. There are currently seven parts to the Lisp FAQ:
  41.    1. Introductory Matter and Bibliography of Introductions and References
  42.    2. General Questions
  43.    3. Common Programming Pitfalls
  44.    4. Lisp Implementations and Mailing Lists
  45.    5. Object-oriented Programming in Lisp
  46.    6. FTP Archives and Resources
  47.    7. Lisp Window Systems and GUIs
  48. All parts are posted to comp.lang.lisp. Part 5 is cross-posted to the
  49. comp.lang.clos newsgroup. 
  50.  
  51. Topics Covered (Part 1):
  52.  
  53.   [1-0]   What is the purpose of this newsgroup?
  54.   [1-1]   What is the difference between Scheme and Common Lisp?
  55.   [1-2]   What documentation is available on Lisp? How can I learn Lisp?
  56.   [1-3]   How can I improve my Lisp programming style and coding efficiency?
  57.   [1-4]   Where can I learn about implementing Lisp interpreters and compilers?
  58.   [1-5]   What does CLOS, PCL, X3J13, CAR, CDR, ... mean? 
  59.   [1-6]   Lisp Job Postings
  60.  
  61. Topics Covered (Part 2):
  62.  
  63.   [2-1]   Is there a GNU-Emacs interface to Lisp?
  64.   [2-2]   When should I use a hash table instead of an association list?
  65.   [2-3]   What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  66.   [2-4]   Is Lisp inherently slower than more conventional languages such as C?
  67.   [2-5]   Why does Common Lisp have "#'"?
  68.   [2-6]   How do I call non-Lisp functions from Lisp?
  69.   [2-7]   Can I call Lisp functions from other languages?
  70.   [2-8]   I want to call a function in a package that might not exist at
  71.           compile time. How do I do this?  
  72.   [2-9]   What is CDR-coding?
  73.   [2-10]  What is garbage collection?
  74.   [2-11]  How do I save an executable image of my loaded Lisp system?
  75.           How do I run a Unix command in my Lisp?
  76.           How do I get the current directory name from within a Lisp program?
  77.   [2-12]  I'm porting some code from a Symbolics Lisp machine to some
  78.           other platform, and there are strange characters in the code.
  79.           What do they mean?  
  80.   [2-13]  History: Where did Lisp come from?
  81.   [2-14]  How do I find the argument list of a function?
  82.           How do I get the function name from a function object?
  83.   [2-15]  How can I have two Lisp processes communicate via unix sockets?
  84.   [2-16]  How can I create a stream that acts like UNIX's /dev/null
  85.           (i.e., gobbles any output and immediately signals EOF on
  86.           input operations)?
  87.  
  88. Common Pitfalls (Part 3):
  89.  
  90.   [3-0]  Why does (READ-FROM-STRING "foobar" :START 3) return FOOBAR
  91.          instead of BAR?  
  92.   [3-1]  Why can't it deduce from (READ-FROM-STRING "foobar" :START 3)
  93.          that the intent is to specify the START keyword parameter
  94.          rather than the EOF-ERROR-P and EOF-VALUE optional parameters?   
  95.   [3-2]  Why can't I apply #'AND and #'OR?
  96.   [3-3]  I used a destructive function (e.g. DELETE, SORT), but it
  97.          didn't seem to work.  Why? 
  98.   [3-4]  After I NREVERSE a list, it's only one element long.  After I
  99.          SORT a list, it's missing things.  What happened? 
  100.   [3-5]  Why does (READ-LINE) return "" immediately instead of waiting
  101.          for me to type a line?  
  102.   [3-6]  I typed a form to the read-eval-print loop, but nothing happened. Why?
  103.   [3-7]  DEFMACRO doesn't seem to work.
  104.          When I compile my file, LISP warns me that my macros are undefined
  105.          functions, or complains "Attempt to call <function> which is 
  106.          defined as a macro.
  107.   [3-8]  Name conflict errors are driving me crazy! (EXPORT, packages)
  108.   [3-9]  Closures don't seem to work properly when referring to the
  109.          iteration variable in DOLIST, DOTIMES and DO.
  110.   [3-10] What is the difference between FUNCALL and APPLY?
  111.   [3-11] Miscellaneous things to consider when debugging code.
  112.   [3-12] When is it right to use EVAL?
  113.   [3-13] Why does my program's behavior change each time I use it?
  114.   [3-14] When producing formatted output in Lisp, where should you put the
  115.          newlines (e.g., before or after the line, FRESH-LINE vs TERPRI,
  116.          ~& vs ~% in FORMAT)?
  117.   [3-15] I'm using DO to do some iteration, but it doesn't terminate. 
  118.   [3-16] My program works when interpreted but not when compiled!
  119.  
  120. Lisp Implementations and Mailing Lists (Part 4):
  121.  
  122.   [4-0]   Free Common Lisp implementations.
  123.   [4-1]   Commercial Common Lisp implementations.
  124.   [4-2]   Scheme Implementations
  125.   [4-4]   Free Implementations of Other Lisp Dialects
  126.   [4-5]   Commercial Implementations of Other Lisp Dialects
  127.   [4-6]   What is Dylan?
  128.   [4-7]   What is Pearl Common Lisp?
  129.   [4-9]   What Lisp-related discussion groups and mailing lists exist?
  130.   [4-10]  ANSI Common Lisp -- Where can I get a copy of the draft standard?
  131.  
  132. Object-oriented Programming in Lisp (Part 5):
  133.  
  134.   [5-0]   What is CLOS (PCL) and where can I get it?
  135.           How do you pronounce CLOS?
  136.   [5-1]   What documentation is available about object-oriented
  137.           programming in Lisp?  
  138.   [5-2]   How I write a function that can access defstruct slots by
  139.           name?  I would like to write something like 
  140.           (STRUCTURE-SLOT <object> '<slot-name>).   
  141.   [5-3]   How can I list all the CLOS instances in a class?
  142.   [5-4]   How can I store data and CLOS instances (with possibly circular
  143.           references) on disk so that they may be retrieved at some later
  144.           time?
  145.   [5-5]   Given the name of a class, how can I get the names of its slots?
  146.   [5-6]   Free CLOS software.
  147.  
  148. FTP Resources (Part 6):
  149.  
  150.   [6-0] General information about FTP Resources for Lisp
  151.   [6-1] Repositories of Lisp Software
  152.   [6-3] Publicly Redistributable Lisp Software
  153.   [6-6] Formatting code in LaTeX
  154.   [6-7] Where can I get an implementation of Prolog in Lisp?
  155.  
  156. Lisp Window Systems and GUIs (Part 7):
  157.   [7-1] How can I use the X Window System or other GUIs from Lisp?
  158.   [7-2] What Graphers/Browsers are available?
  159.  
  160. Search for \[#\] to get to question number # quickly.
  161.  
  162. Recent Changes:
  163.  
  164. ;;; 1.34:
  165. ;;; 13-MAY-93 mk    Corrected Austin Code Works address.
  166. ;;; 19-MAY-93 mk    Added entry on Deftable to part 6.
  167. ;;; 21-MAY-93 mk    Added EJFLP to mailing lists in part 4.
  168. ;;; 31-MAY-93 mk    Added entry on FRAPPS, a theorem prover, to part 6.
  169. ;;;  2-JUN-93 mk    Updated Franz Allegro entry.
  170. ;;;  2-JUN-93 mk    Changed ftp address for cli.com.
  171. ;;;  7-JUN-93 mk    Split out Lisp Window Systems and GUIs (6-5) to form part 7
  172. ;;;                 of the FAQ.
  173. ;;;  7-JUN-93 mk    Added [7-2] What Graphers/Browsers are available?
  174.  
  175.  
  176. Introduction:
  177.  
  178. Certain questions and topics come up frequently in the various network
  179. discussion groups devoted to and related to Lisp.  This file/article is
  180. an attempt to gather these questions and their answers into a convenient
  181. reference for Lisp programmers.  It (or a reference to it) is posted
  182. periodically.  The hope is that this will cut down on the user time and
  183. network bandwidth used to post, read and respond to the same questions
  184. over and over, as well as providing education by answering questions
  185. some readers may not even have thought to ask.
  186.  
  187. This is not a Lisp tutorial, nor is it an exhaustive list of all Lisp
  188. intricacies.  Lisp is a very powerful and expressive language, but with
  189. that power comes many complexities.  This list attempts to address the
  190. ones that average Lisp programmers are likely to encounter.  If you are
  191. new to Lisp, see the answer to the question "How can I learn Lisp?".
  192.  
  193. The latest version of this file is available via anonymous FTP from CMU
  194. and Thinking Machines: 
  195.  
  196.    To obtain the files from CMU, connect by anonymous ftp to any CMU CS
  197.    machine (e.g., ftp.cs.cmu.edu [128.2.206.173]), using username
  198.    "anonymous" and password "name@host". The files lisp-faq-1.text,
  199.    lisp-faq-2.text, lisp-faq-3.text, lisp-faq-4.text, lisp-faq-5.text,
  200.    lisp-faq-6.text and lisp-faq-7.text are located in the directory
  201.        /afs/cs.cmu.edu/user/mkant/Public/Lisp-Utilities/
  202.    [Note: You must cd to this directory in one atomic operation, as
  203.    some of the superior directories on the path are protected from
  204.    access by anonymous ftp.] If your site runs the Andrew File System,
  205.    you can just cp the files directly without bothering with FTP.
  206.  
  207.    To obtain the files from Thinking Machines, ftp them from ftp.think.com,
  208.    in the directory /public/think/lisp/. The file faq.text contains all the
  209.    parts of the FAQ in one file. In addition, specific versions of the FAQ
  210.    are available as faq-<version>.text.
  211.  
  212. The FAQ postings are also archived in the periodic posting archive on
  213. rtfm.mit.edu [18.70.0.224]. Look in the anonymous ftp directory
  214. /pub/usenet/news.answers/ in the subdirectory lisp-faq/. If you do not
  215. have anonymous ftp access, you can access the archive by mail server
  216. as well.  Send an E-mail message to mail-server@rtfm.mit.edu
  217. with "help" and "index" in the body on separate lines for more
  218. information.
  219.  
  220. Unless otherwise specified, the Lisp dialect referred to is Common Lisp,
  221. as defined by "Common Lisp: the Language" (aka "CLtL1") as well as
  222. corrections (but not enhancements) from "Common Lisp: the Language, 2nd
  223. Edition" (aka "CLtL2"), both by Guy L. Steele, Jr. and published by
  224. Digital Press. Note that CLtL2 is NOT an official specification for
  225. the language; ANSI Committee X3J13 is preparing such a specification.
  226. See question [4-10] for information on the status of the ANSI
  227. specification for Common Lisp. Enhancements such as CLOS, conditions,
  228. and the LOOP macro will be referred to separately.
  229.  
  230. ----------------------------------------------------------------
  231. Subject: [1-0] What is the purpose of this newsgroup?
  232.  
  233. The newsgroup comp.lang.lisp exists for general discussion of
  234. topics related to the programming language Lisp. For example, possible
  235. topics can include (but are not necessarily limited to):
  236.    announcements of Lisp books and products
  237.    discussion of programs and utilities written in Lisp
  238.    discussion of portability issues
  239.    questions about possible bugs in Lisp implementations
  240.    problems porting an implementation to some architecture
  241. Postings should be of general interest to the Lisp community. See also
  242. question [4-9]. Postings asking for solutions to homework problems are
  243. inappropriate. 
  244.  
  245. Every so often, somebody posts an inflammatory message, such as
  246.    My programming language is better than yours (Lisp vs. C/Prolog/Scheme). 
  247.    Loop (or Series) should/shouldn't be part of the language.
  248. These "religious" issues serve no real purpose other than to waste
  249. bandwidth. If you feel the urge to respond to such a post, please do
  250. so through a private e-mail message. 
  251.  
  252. Questions about object oriented programming in Lisp should be directed
  253. to the newsgroup comp.lang.clos. Similarly, questions about the
  254. programming language Scheme should be directed to the newsgroup
  255. comp.lang.scheme. Discussion of functional programming language issues
  256. should be directed to the newsgroup comp.lang.functional. Discussion
  257. of AI programs implemented in Lisp should sometimes be cross-posted to
  258. the newsgroup comp.ai.
  259.  
  260. ----------------------------------------------------------------
  261. Subject: [1-1] What is the difference between Scheme and Common Lisp?
  262.  
  263. Scheme is a dialect of Lisp that stresses conceptual elegance and
  264. simplicity. It is specified in R4RS and IEEE standard P1178. (See
  265. the Scheme FAQ for details on standards for Scheme.) Scheme is much
  266. smaller than Common Lisp; the specification is about 50 pages,
  267. compared to Common Lisp's 1300 page draft standard. (See question
  268. [4-10] for details on standards for Common Lisp.) Advocates of Scheme
  269. often find it amusing that the Scheme standard is shorter than the
  270. index to CLtL2. 
  271.  
  272. Scheme is often used in computer science curricula and programming
  273. language research, due to its ability to represent many programming
  274. abstractions with its simple primitives. Common Lisp is often used for
  275. real world programming because of its large library of utility
  276. functions, a standard object-oriented programming facility (CLOS), and
  277. a sophisticated condition handling system.
  278.  
  279. See the Scheme FAQ for information about object-oriented programming
  280. in Scheme. 
  281.  
  282. In Common Lisp, a simple program would look something like the
  283. following:
  284.  
  285.    (defun fact (n)
  286.      (if (< n 2)
  287.          1
  288.          (* n (fact (1- n)))))
  289.  
  290. In Scheme, the equivalent program would like like this:
  291.  
  292.    (define fact
  293.      (lambda (n)
  294.        (if (< n 2)
  295.        1
  296.      (* n (fact (- n 1))))))
  297.  
  298. Experienced Lisp programmers might write this program as follows in order
  299. to allow it to run in constant space:
  300.  
  301.    (defun fact (n)
  302.      (labels ((tail-recursive-fact (counter accumulator)
  303.         (if (> counter n)
  304.             accumulator
  305.             (tail-recursive-fact (1+ counter)
  306.                      (* counter accumulator)))))
  307.        (tail-recursive-fact 1 1)))
  308.  
  309. Whereas in Scheme the same computation could be written as follows:
  310.  
  311.    (define fact
  312.      (lambda (n)
  313.        (letrec ((tail-recursive-fact
  314.          (lambda (counter accumulator)
  315.            (if (> counter n)
  316.                accumulator
  317.              (tail-recursive-fact (+ counter 1)
  318.                                           (* counter accumulator))))))
  319.            (tail-recursive-fact 1 1))))
  320.  
  321. or perhaps (using IEEE named LETs):
  322.  
  323.    (define fact
  324.      (lambda (n)
  325.        (let loop ((counter n)
  326.           (accumulator 1))
  327.         (if (< counter 2)
  328.         accumulator
  329.           (loop (- counter 1)
  330.             (* accumulator counter))))))
  331.  
  332. Some Schemes allow one to use the syntax (define (fact n) ...) instead
  333. of (define fact (lambda (n) ...)).
  334.  
  335. ----------------------------------------------------------------
  336. Subject: [1-2] What documentation is available on Lisp? 
  337.                How can I learn Lisp?
  338.  
  339. There are several good Lisp introductions and tutorials:
  340.  
  341.    1. David S. Touretzky
  342.       "Common Lisp: A Gentle Introduction to Symbolic Computation"
  343.       Benjamin/Cummings Publishers, Redwood City, CA, 1990. 592 pages.
  344.       ISBN 0-8053-0492-4. 
  345.            Perhaps the best tutorial introduction to the language. It has
  346.            clear and correct explanations, and covers some fairly advanced
  347.            topics. The book is an updated Common Lisp version of the 1984
  348.            edition published by Harper and Row Publishers. 
  349.  
  350.            Three free Lisp educational tools which were used in the book --
  351.            Evaltrace, DTRACE and SDRAW -- are available by anonymous ftp from
  352.            b.gp.cs.cmu.edu:/usr/dst/public/{lisp,evaltrace}. Evaltrace is a
  353.            graphical notation for explaining how evaluation works and is
  354.            described in "Visualizing Evaluation in Applicative Languages" by
  355.            David S. Touretzky and Peter Lee, CACM 45-59, October 1992. DTRACE
  356.            is a "detailed trace" which provides more information than the 
  357.            tracing tools provided with most Common Lisp implementations. SDRAW
  358.            is a read-eval-draw loop that evaluates Lisp expressions
  359.            and draws the result as a cons cell diagram (for both X11 and ascii
  360.            terminals). Also available is PPMX, a tool for pretty printing
  361.        macro expansions.
  362.  
  363.    2. Robert Wilensky
  364.       "Common LISPcraft"
  365.       W. W. Norton, 1986. 385 pages.
  366.  
  367.    3. Wade L. Hennessey 
  368.       "Common Lisp"
  369.       McGraw-Hill, 1989. 395 pages.
  370.            Fairly good, but jumps back and forth from the simple to the
  371.            complex rather quickly, with no clear progression in difficulty.
  372.  
  373.    4. Laurent Siklossy
  374.       "Let's Talk LISP"
  375.       Prentice-Hall, NJ, 1976. 237 pages.
  376.            Good introduction, but quite out of date.
  377.  
  378.    5. Stuart C. Shapiro
  379.       "Common Lisp: An Interactive Approach"
  380.       Computer Science Press/W.H. Freeman, New York, 1992.
  381.       ISBN 0-7167-8218-9
  382.  
  383. Other introductions to Lisp include:
  384.  
  385.    1. A. A. Berk.
  386.       "LISP, The Language of Artificial Intelligence"
  387.       Van Nostrand Reinhold, 1985. 160 pages.
  388.  
  389.    2. Paul Y. Gloess.
  390.       "An Alfred handy guide to Understanding LISP"
  391.       Alfred Publishers (Sherman Oaks, CA), 1982. 64 pages.
  392.  
  393.    3. Ward D. Maurer.
  394.       "The Programmer's Introduction to LISP"
  395.       American Elsevier, 1972. 112 pages.
  396.  
  397.    4. Hank Bromley and Richard Lamson.
  398.       "LISP Lore: A Guide to Programming the LISP Machine"
  399.       Kluwer Academic (Boston), 1987. 337 pages.
  400.  
  401.    5. Sharam Hekmatpour.
  402.       "Introduction to LISP and Symbol Manipulation"
  403.       Prentice Hall (New York), 1988. 303 pages.
  404.  
  405.    6. Deborah G. Tatar
  406.       "A programmer's guide to Common Lisp"
  407.       Digital Press, 1987. 327 pages. ISBN 0-932376-87-8.
  408.            Good introduction on Common Lisp.
  409.  
  410.    7. Timothy Koschmann
  411.       "The Common Lisp Companion"
  412.       John Wiley & Sons, 1990. ISBN 0-471-503-8-8.
  413.            Targeted for those with some programming experience who wish to 
  414.            learn draft-ANSI Common Lisp, including CLOS and the CL condition 
  415.            system. Examples progress incrementally from simple numerical 
  416.            calculation all the way to a logic-programming extension to CL.
  417.   
  418. More advanced introductions to Lisp and its use in Artificial
  419. Intelligence include:
  420.  
  421.    1. Peter Norvig.
  422.       "Paradigms of AI Programming: Case Studies in Common Lisp"
  423.       Morgan Kaufmann, 1992. 946 pages. ISBN 1-55860-191-0.
  424.  
  425.         Provides an in-depth exposition of advanced AI programming techniques
  426.         and includes large-scale detailed examples. The book is the most
  427.         advanced AI/Common-Lisp programming text and reference currently
  428.         available, and hence is not for the complete novice.  It focuses on the
  429.         programming techniques necessary for building large AI systems,
  430.         including object-oriented programming, and has a strong performance
  431.         orientation.
  432.  
  433.         The text is marked by its use of "non-toy" examples to illustrate the
  434.         techniques. All of the examples are written in Common Lisp, and copies
  435.         of the source code are available by anonymous ftp from
  436.         unix.sri.com:pub/norvig and on disk in Macintosh or DOS format from
  437.         the publisher. Some of the techniques described include rule-based
  438.         pattern matching (GPS, Eliza, a subset of Macsyma, the Emycin expert
  439.         system shell), constraint propagation and backtracking (Waltz
  440.         line-labelling), alpha-beta search (Othello), natural language
  441.         processing (top-down, bottom-up and chart parsing), logic-programming
  442.         (unification and Prolog), interpreters and compilers for Scheme, and
  443.         object-oriented programming (CLOS).
  444.  
  445.         The examples are also used to illustrate good programming style and
  446.         efficiency. There is a guide to trouble-shooting and debugging Lisp
  447.         programs, a style guide, and a discussion of portability problems.
  448.         Some of the efficiency techniques described include memoization,
  449.         data indexing, compilation, delaying computation, proper use of
  450.         declarations, avoiding garbage collection, and choosing and using the
  451.         correct data structure.
  452.  
  453.         The book also serves as an advanced introduction to Common Lisp, with
  454.         sections on the Loop macro, CLOS and sequences, and some coverage of 
  455.         error handling, series, and the package facility.
  456.  
  457.    2. Eugene Charniak, Christopher K. Riesbeck, Drew V. McDermott
  458.       and James R. Meehan.
  459.       "Artificial Intelligence Programming", 2nd edition.
  460.       Lawrence Erlbaum Associates (Hillsdale, NJ), 1987. 533 pages.
  461.            Provides many nice code fragments, all of which are written
  462.            in Common Lisp. The first half of the book covers topics
  463.            like macros, the reader, data structures, control structures,
  464.            and defstructs. The second half of the book describes
  465.            programming techniques specific to AI, such as
  466.            discrimination nets, production systems, deductive database
  467.            retrieval, logic programming, and truth maintenance.
  468.  
  469.    3. Patrick H. Winston and Berthold K. P. Horn.
  470.       "LISP", 3rd edition.
  471.       Addison-Wesley (Reading, MA), 1989. 611 pages. ISBN 0-201-08319-1
  472.            Covers the basic concepts of the language, but also gives a lot
  473.            of detail about programming AI topics such as rule-based expert
  474.            systems, forward chaining, interpreting transition trees, 
  475.            compiling transition trees, object oriented programming,
  476.            and finding patterns in images. Not a tutorial. Has many
  477.            good examples. Source code for the examples is available by
  478.            anonymous ftp from ftp.ai.mit.edu:/pub/lisp3/. More
  479.            detailed versions are in /pub/ai3/. (The code runs in
  480.            Lucid, Allegro, KCL, GCLisp, MCL, Symbolics Genera. Send mail
  481.            with subject line "help" to ai3@ai.mit.edu for more information.)
  482.  
  483.    4. Rodney A. Brooks.
  484.       "Programming in Common Lisp"
  485.       Wiley, 1985. 303 pages.
  486.  
  487.    5. John R. Anderson, Albert T. Corbett, and Brian J. Reiser.
  488.       "Essential LISP"
  489.       Addison-Wesley (Reading, MA), 1987. 352 pages.
  490.            Concentrates on how to use Lisp with iteration and recursion.
  491.  
  492.    6. Robert D. Cameron and Anthony H. Dixon
  493.       "Symbolic Computing with Lisp"
  494.       Prentice-Hall, 1992, 326 pages. ISBN 0-13-877846-9.
  495.            The book is intended primarily as a third-year computer science
  496.            text. In terms of programming techniques, it emphasizes recursion
  497.            and induction, data abstraction, grammar-based definition of Lisp
  498.            data structures and functional programming style. It uses
  499.            two Lisp languages: 
  500.                 (1) a purely functional subset of Lisp called Small Lisp and
  501.                 (2) Common Lisp.
  502.            An MS-DOS interpreter for Small Lisp (including source) is
  503.            provided with the book.  It considers applications of Lisp
  504.            to formal symbolic data domains: algebraic expressions,
  505.            logical formulas, grammars and programming languages. 
  506.  
  507.    7. Hasemer and Domingue.
  508.       "Common Lisp Programming for Artificial Intelligence"
  509.       Addison-Wesley, 1989.
  510.  
  511.    8. Steven Tanimoto
  512.       "The Elements of Artificial Intelligence: An Introduction Using Lisp"
  513.       Computer Science Press, Rockville, MD, 1987, 530 pages.
  514.  
  515.    9. Patrick R. Harrison
  516.       "Common Lisp and Artificial Intelligence"
  517.       Prentice Hall, 1990. ISBN 0-13-155243
  518.  
  519.   10. Rajeev Sangal
  520.       "Programming Paradigms in Lisp"
  521.       McGraw-Hill, 1991. ISBN 0-07-054666-5.
  522.  
  523. General Lisp reference books include:
  524.  
  525.    1. Guy L. Steele
  526.       "Common Lisp: The Language" [CLtL1]
  527.       Digital Press, 1984. 465 pages. ISBN 0-932376-41-X.
  528.  
  529.    2. Guy L. Steele
  530.       "Common Lisp: The Language, 2nd Edition" [CLtL2]
  531.       Digital Press, 1990. 1029 pages. ISBN 1-55558-041-6.
  532.  
  533.    3. Franz Inc. 
  534.       "Common Lisp: The Reference"
  535.       Addison-Wesley, Reading, MA 1988. ISBN 0-201-11458-5
  536.            Entries on Lisp (CLtL1) functions in alphabetical order.
  537.  
  538. Lisp periodicals include:
  539.         
  540.    1. LISP Pointers.
  541.       Published by ACM SIGPLAN six times a year. Volume 1, Number 1
  542.       was April-May 1987. 
  543.       Subscriptions: ACM Members $12; ACM Student Members $7; Non-ACM
  544.       members $25. Mail checks payable to the ACM to ACM Inc., PO Box
  545.       12115, Church Street Station, New York, NY 10249.
  546.  
  547.    2. LISP and Symbolic Computation, Kluwer Academic Press. Volume 1
  548.       was published in 1989. (jlz@lucid.com is the editor).  ISSN 0892-4635.
  549.       Subscriptions: Institutions $169; Individuals $80. Add $8 for
  550.       air mail. Kluwer Academic Publishers, PO Box 322, 3300 AH Dordrecht, 
  551.       The Netherlands, or Kluwer Academic Publishers, PO Box 358, Accord
  552.       Station, Hingham, MA 02018-0358. 
  553.  
  554.    3. Proceedings of the biannual ACM Lisp and Functional Programming
  555.       Conference. (First one was in 1980.)
  556.  
  557.    4. Proceedings of the annual Lisp Users and Vendors Conference.
  558.  
  559. Implementation-specific questions:
  560.  
  561.    1. Lucid. See the wizards.doc file that comes with the Lucid
  562.       release. It describes functions, macros, variables and constants that
  563.       are not official parts of the product and are not supported.
  564.       Constructs described in this file include: the interrupt facility, the
  565.       source file recording facility, the resource facility, multitasking,
  566.       writing your own streams, lisp pipes, i/o buffers, the compiler,
  567.       floating-point functions, memory management, debugger information, the
  568.       window tool kit, extensions to the editor, the foreign function
  569.       interface, clos information, delivery toolkit information, and Lucid
  570.       lisp training classes. The wizards.doc file also covers i/o
  571.       constructs, functions for dealing with DEFSTRUCT, functions and
  572.       constants for dealing with procedure objects, functions and constants
  573.       for dealing with code objects, function for mapping objects,
  574.       additional keyword argument to DISKSAVE, function used in the
  575.       implementation of arrays, function for monitor-specific behavior for a
  576.       process, additional keyword argument to RUN-PROGRAM, and load-time
  577.       evaluation.
  578.  
  579. Many books on Scheme are worth reading even if you use Common Lisp,
  580. because many of the issues are similar. Scheme is a simpler language
  581. to learn, so it is often used in introductory computer science
  582. classes.  See the Scheme FAQ for a list of introductions and
  583. references for Scheme. The two key introductions are Abelson and
  584. Sussman's "Structure and Interpretation of Computer Programs" and 
  585. Friedman and Felleisen's "The Little LISPer". 
  586.  
  587. Special Topics:
  588.  
  589.    Garbage Collection:
  590.  
  591.       Wilson, Paul R., "Uniprocessor Garbage Collection Techniques"
  592.       Proceedings of the 1992 International Workshop on Memory Management.
  593.       Springer Lecture Notes #637. Surveys garbage collection techniques. 
  594.       Includes an excellent bibliography. Available by anonymous ftp from
  595.          cs.utexas.edu:pub/garbage/gcsurvey.ps.
  596.       The BibTeX format of the bibliography is also available in this
  597.       directory, along with several other papers. Contact wilson@cs.utexas.edu
  598.       for more info.
  599.  
  600. ----------------------------------------------------------------
  601. Subject: [1-3] How can I improve my Lisp programming style and 
  602.                coding efficiency?
  603.  
  604. There are several books about Lisp programming style, including:
  605.    
  606.    1. Molly M. Miller and Eric Benson
  607.       "Lisp Style and Design"
  608.       Digital Press, 1990. 214 pages. ISBN 1-55558-044-0.
  609.            How to write large Lisp programs and improve Lisp programming 
  610.            style. Uses the development of Lucid CL as an example. 
  611.  
  612.    2. Robin Jones, Clive Maynard, and Ian Stewart.
  613.       "The Art of Lisp Programming"
  614.       Springer-Verlag, 1989. 169 pages.
  615.  
  616.    3. W. Richard Stark.
  617.       "LISP, Lore, and Logic: an algebraic view of LISP
  618.        programming, foundations, and applications"
  619.       Springer-Verlag, 1990. 278 pages. ISBN 0-387-97072-X
  620.            Self-modifying code, self-reproducing programs, etc.
  621.  
  622.    4. CMU CL User's Manual, Chapter 7, (talks about writing
  623.       efficient code). It is available by anonymous ftp from any CMU CS 
  624.       machine (e.g., ftp.cs.cmu.edu [128.2.206.173]) as the file
  625.         /afs/cs.cmu.edu/project/clisp/docs/cmu-user/cmu-user.ps 
  626.       [when getting this file by anonymous ftp, one must cd to 
  627.       the directory in one atomic operation, as some of the superior
  628.       directories on the path are protected from access by anonymous ftp.]
  629.  
  630.    5. See also Norvig's book, SICP (Abelson & Sussman), SAP
  631.       (Springer and Friedman).
  632.  
  633.    6. Hallvard Tretteberg's Lisp Style Guide is available by anonymous
  634.       ftp in ftp.think.com:/public/think/lisp/style-guide.text. There is
  635.       a fair bit of overlap between Hallvard's style guide and the notes
  636.       below and in part 3 of this FAQ.
  637.  
  638. Here are some general suggestions/notes about improving Lisp
  639. programming style, readability, correctness and efficiency:
  640.  
  641.    General Programming Style Rules:
  642.  
  643.       - Write short functions, where each function provides a single,
  644.         well-defined operation. Small functions are easier to
  645.         read, write, test, debug, and understand.
  646.  
  647.       - Use descriptive variable and function names. If it isn't clear
  648.         from the name of a function or variable what its purpose is,
  649.         document it with a documentation string and a comment. In fact,
  650.         even if the purpose is evident from the name, it is still worth
  651.         documenting your code.
  652.  
  653.       - Don't write Pascal (or C) code in Lisp. Use the appropriate
  654.         predefined functions -- look in the index to CLtL2, or use the
  655.         APROPOS and DESCRIBE functions. Don't put a close parenthesis
  656.         on a line by itself -- this can really aggravate programmers
  657.         who grew up on Lisp. Lisp-oriented text editors include tools
  658.         for ensuring balanced parentheses and for moving across 
  659.         pairs of balanced parentheses. You don't need to stick
  660.         comments on close parentheses to mark which expression they close.
  661.  
  662.       - Use proper indentation -- you should be able to understand
  663.         the structure of your definitions without noticing the parentheses. 
  664.         In general, the way one indents a form is controlled by the
  665.         first symbol of the form. In DEFUNs, for example, one puts the
  666.         symbol DEFUN, the function name, and the argument list all on
  667.         the same line. If the argument list is too long, one can break
  668.         it at one of the lambda keywords. Following the argument list,
  669.         one inserts a carriage return and lists the expressions in the
  670.         body of the definition, with each form starting on its own
  671.         line indented three spaces relative to the open parenthesis of
  672.         the parent (in this case the DEFUN). This general style -- of
  673.         putting all the significant elements of a form on a single
  674.         line, followed by a carriage return and the indented body --
  675.         holds for many Lisp constructs. There are, of course, variations,
  676.         such as keeping the first clause on the same line as the COND
  677.         or CASE symbol, and the rules are relaxed in different ways to
  678.         keep line lengths to a manageable size. If you find yourself having
  679.         trouble fitting everything in even with line breaking and
  680.         relaxing the rules, either your function names are too long or your
  681.         code isn't very modular. You should perceive this as a signal that
  682.         you need to break up your big definitions into smaller chunks, each
  683.         with a clearly defined purpose, and possibly replace long function
  684.         names with concise but apt shorter ones.
  685.  
  686.       - Use whitespace appropriately. Use whitespace to separate
  687.         semantically distinct code segments, but don't use too much
  688.         whitespace. For example,
  689.            GOOD: 
  690.           (defun foo (x y)
  691.         (let ((z (+ x y 10)))
  692.           (* z z)))
  693.  
  694.            BAD: 
  695.               (defun foo(x y)(let((z(+ x y 10)))(* z z)))
  696.  
  697.           (defun foo ( x  y )
  698.         (let ( ( z (+ x y 10) ) )
  699.           ( * z z )
  700.           )
  701.         )    
  702.          Although the Lisp reader and compiler don't care which you
  703.          use, most experienced Lisp programs find the first example much easier
  704.          to read than the last two.
  705.  
  706.        - Don't use line lengths greater than 80 characters. People who
  707.          write code using Zmacs on Symbolics Lisp Machines are notoriously
  708.          guilty of violating this rule, because the CPT6 font allows
  709.          one to squeeze a tremendous amount of code on the display,
  710.          especially if one spreads the code out horizontally. This
  711.          makes it more difficult to read when printed out or read on
  712.          an 80x24 xterm window. In fact, use a line length of 72 characters
  713.          because it leaves a strip of white space at the edge of the window.
  714.  
  715.    The following functions often abused or misunderstood by novices. 
  716.    Think twice before using any of these functions.
  717.  
  718.       - EVAL. Novices almost always misuse EVAL. When experts use
  719.         EVAL, they often would be better off using APPLY, FUNCALL, or
  720.         SYMBOL-VALUE. Use of EVAL when defining a macro should set off
  721.         a warning bell -- macro definitions are already evaluated
  722.         during expansion. See also the answer to question 3-12.
  723.         The general rule of thumb about EVAL is: if you think you need
  724.         to use EVAL, you're probably wrong.
  725.  
  726.       - PROGV. PROGV binds dynamic variables and is often misused in
  727.         conjunction with EVAL, which uses the dynamic environment. 
  728.         In general, avoid unnecessary use of special variables.
  729.         PROGV is mainly for writing interpreters for languages embedded
  730.         in Lisp. If you want to bind a list of values to a list of
  731.         lexical variables, use
  732.             (MULTIPLE-VALUE-BIND (..) (VALUES-LIST ..) ..)
  733.         or
  734.             (MULTIPLE-VALUE-SETQ (..) (VALUES-LIST ..))
  735.         instead. Most decent compilers can optimize this expression. 
  736.         However, use of this idiom is not to be encouraged unless absolutely
  737.         necessary.
  738.  
  739.       - CATCH and THROW. Often a named BLOCK and RETURN-FROM are
  740.         more appropriate. Use UNWIND-PROTECT when necessary.
  741.  
  742.       - Destructive operations, such as NCONC, SORT, DELETE,
  743.         RPLACA, and RPLACD, should be used carefully and sparingly.
  744.         In general, trust the garbage collector: allocate new
  745.         data structures when you need them.
  746.  
  747.    To improve the readability of your code,
  748.  
  749.       - Don't use any C{A,D}R functions with more than two
  750.         letters between the C and the R. When nested, they become
  751.         hard to read. If you have complex data structures, you
  752.         are often better off describing them with a DEFSTRUCT,
  753.         even if the type is LIST. The data abstraction afforded by
  754.         DEFSTRUCT makes the code much more readable and its purpose
  755.         clearer. If you must use C{A,D}R, try to use
  756.         DESTRUCTURING-BIND instead, or at least SECOND, THIRD, 
  757.         NTH, NTHCDR, etc.
  758.  
  759.       - Use COND instead of IF and PROGN. In general, don't use PROGN if
  760.         there is a way to write the code within an implicit
  761.         PROGN. For example, 
  762.            (IF (FOO X)
  763.                (PROGN (PRINT "hi there") 23)
  764.                34)
  765.         should be written using COND instead.
  766.  
  767.       - Never use a 2-argument IF or a 3-argument IF with a second
  768.         argument of NIL unless you want to emphasize the return value;
  769.         use WHEN and UNLESS instead. You will want to emphasize the
  770.         return value when the IF clause is embedded within a SETQ,
  771.         such as (SETQ X (IF (EQ Y Z) 2 NIL)). If the second argument 
  772.         to IF is the same as the first, use OR instead: (OR P Q) rather
  773.         than (IF P P Q). Use UNLESS instead of (WHEN (NOT ..) ..)
  774.         but not instead of (WHEN (NULL ..) ..).
  775.  
  776.       - Use COND instead of nested IF statements. Be sure to check for
  777.         unreachable cases, and eliminate those cond-clauses.
  778.  
  779.       - Use backquote, rather than explicit calls to LIST, CONS, and
  780.         APPEND, whenever writing a form which produces a Lisp form, but
  781.         not as a general substitute for LIST, CONS and APPEND. LIST, 
  782.         CONS and APPEND usually allocate new storage, but lists produced
  783.         by backquote may involve destructive modification (e.g., ,.).
  784.  
  785.       - Make the names of special (global) variables begin and end
  786.         with an asterisk (*): (DEFVAR *GLOBAL-VARIABLE*)   
  787.         Some programmers will mark the beginning and end of an internal
  788.         global variable with a percent (%) or a period (.).
  789.         Make the names of constants begin and end with a plus (+):
  790.         (DEFCONSTANT +E+ 2.7182818)
  791.         This helps distinguish them from lexical variables. Some people
  792.         prefer to use macros to define constants, since this avoids
  793.         the problem of accidentally trying to bind a symbol declared
  794.         with defconstant.
  795.  
  796.       - If your program is built upon an underlying substrate which is
  797.         implementation-dependent, consider naming those functions and
  798.         macros in a way that visually identifies them, either by placing
  799.         them in their own package, or prepending a character like a %, ., 
  800.         or ! to the function name. Note that many programmers use the
  801.         $ as a macro character for slot access, so it should be avoided
  802.         unless you're using it for that purpose.
  803.  
  804.       - Don't use property lists. Instead, use an explicit hash table.
  805.         This helps avoid problems caused by the symbol being in the wrong
  806.         package, accidental reuse of property keys from other
  807.         programs, and allows you to customize the structure of the table. 
  808.  
  809.       - Use the most specific construct that does the job. This lets
  810.         readers of the code see what you intended when writing the code.
  811.         For example, don't use SETF if SETQ will do (e.g., for lexical
  812.         variables). Use the most specific predicate to test your conditions.
  813.         If you intend for a function to be a predicate, have it return T
  814.         for true, not just non-NIL. 
  815.  
  816.       - When NIL is used as an empty list, use () in your code. When NIL
  817.         is used as a boolean, use NIL. Similarly, use NULL to test for an
  818.         empty list, NOT to test a logical value. Use ENDP to test for the
  819.         end of a list, not NULL.
  820.  
  821.       - Don't use the &AUX lambda-list keyword. It is always clearer to
  822.         define local variables using LET or LET*.
  823.  
  824.       - When using RETURN and RETURN-FROM to exit from a block, don't
  825.         use (VALUES ..) when returning only one value, except if you
  826.         are using it to suppress extra multiple values from the first
  827.         argument. 
  828.  
  829.       - If you want a function to return no values (i.e., equivalent to
  830.         VOID in C), use (VALUES) to return zero values. This signals
  831.         to the reader that the function is used mainly for side-effects.
  832.  
  833.       - (VALUES (VALUES 1 2 3)) returns only the first value, 1.
  834.         You can use (VALUES (some-multiple-value-function ..)) to suppress
  835.         the extra multiple values from the function. Use MULTIPLE-VALUE-PROG1
  836.         instead of PROG1 when the multiple values are significant.
  837.  
  838.       - When using MULTIPLE-VALUE-BIND and DESTRUCTURING-BIND, don't rely
  839.         on the fact that NIL is used when values are missing. This is
  840.         an error in some implementations of DESTRUCTURING-BIND. Instead,
  841.         make sure that your function always returns the proper number of
  842.         values.
  843.  
  844.       - Type the name of external symbols, functions, and variables
  845.         from the COMMON-LISP package in uppercase. This will allow your
  846.     code to work properly in a case-sensitive version of Common Lisp,
  847.         since the print-names of symbols in the COMMON-LISP package
  848.         are uppercase internally. (However, not everybody feels that
  849.     being nice to case-sensitive Lisps is a requirement, so this
  850.     isn't an absolute style rule, just a suggestion.)
  851.  
  852.     Lisp Idioms:
  853.  
  854.       - MAPCAN is used with a function to return a variable number of
  855.     items to be included in an output list. When the function returns zero
  856.     or one items, the function serves as a filter. For example,
  857.        (mapcan #'(lambda (x) (when (and (numberp x) (evenp x)) (list x)))
  858.            '(1 2 3 4 x 5 y 6 z 7))
  859.  
  860.     Documentation:
  861.  
  862.       - Comment your code. Use three semicolons in the left margin before
  863.         the definition for major explanations. Use two semicolons that
  864.         float with the code to explain the routine that follows. Two
  865.         semicolons may also be used to explain the following line when the
  866.         comment is too long for the single semicolon treatment. Use
  867.         a single semicolon to the right of the code to explain a particular
  868.         line with a short comment. The number of semicolons used roughly
  869.         corresponds with the length of the comment. Put at least one blank
  870.         line before and after top-level expressions.
  871.  
  872.       - Include documentation strings in your code. This lets users
  873.         get help while running your program without having to resort to
  874.         the source code or printed documentation. 
  875.  
  876.    Issues related to macros:
  877.  
  878.       - Never use a macro instead of a function for efficiency reasons.
  879.         Declaim the function as inline -- for example, 
  880.           (DECLAIM (INLINE ..))
  881.         This is *not* a magic bullet -- be forewarned that inline
  882.         expansions can often increase the code size dramatically. INLINE
  883.         should be used only for short functions where the tradeoff is
  884.         likely to be worthwhile: inner loops, types that the compiler
  885.         might do something smart with, and so on.
  886.  
  887.       - When defining a macro that provides an implicit PROGN, use the
  888.         &BODY lambda-list keyword instead of &REST.
  889.  
  890.       - Use gensyms for bindings within a macro, unless the macro lets
  891.         the user explicitly specify the variable. For example:
  892.             (defmacro foo ((iter-var list) body-form &body body)
  893.               (let ((result (gensym "RESULT")))
  894.                 `(let ((,result nil))
  895.                    (dolist (,iter-var ,list ,result)
  896.                      (setq ,result ,body-form)
  897.                      (when ,result
  898.                         ,@body)))))        
  899.         This avoids errors caused by collisions during macro expansion
  900.         between variable names used in the macro definition and in the
  901.         supplied body.
  902.  
  903.       - Use a DO- prefix in the name of a macro that does some kind of
  904.         iteration, WITH- when the macro establishes bindings, and
  905.         DEFINE- or DEF- when the macro creates some definitions. Don't
  906.         use the prefix MAP- in macro names, only in function names.
  907.  
  908.       - Don't create a new iteration macro when an existing function
  909.         or macro will do.
  910.  
  911.       - Don't define a macro where a function definition will work just
  912.         as well -- remember, you can FUNCALL or MAPCAR a function but 
  913.         not a macro.
  914.  
  915.       - The LOOP and SERIES macros generate efficient code. If you're
  916.         writing a new iteration macro, consider learning to use one
  917.         of them instead.
  918.   
  919.    File Modularization:
  920.  
  921.       - If your program involves macros that are used in more than one
  922.         file, it is generally a good idea to put such macros in a separate
  923.         file that gets loaded before the other files. The same things applies
  924.         to primitive functions. If a macro is complicated, the code that
  925.         defines the macro should be put into a file by itself. In general, if
  926.         a set of definitions form a cohesive and "independent" whole, they
  927.         should be put in a file by themselves, and maybe even in their own
  928.         package. It isn't unusual for a large Lisp program to have files named
  929.         "site-dependent-code", "primitives.lisp", and "macros.lisp". If a file
  930.         contains primarily macros, put "-macros" in the name of the file.
  931.  
  932.    Stylistic preferences:
  933.  
  934.       - Use (SETF (CAR ..) ..) and (SETF (CDR ..) ..) in preference to
  935.         RPLACA and RPLACD. Likewise (SETF (GET ..) ..) instead of PUT.
  936.  
  937.       - Use INCF, DECF, PUSH and POP instead instead of the corresponding
  938.         SETF forms.
  939.  
  940.       - Many programmers religiously avoid using CATCH, THROW, BLOCK,
  941.         PROG, GO and TAGBODY.  Tags and go-forms should only be necessary
  942.         to create extremely unusual and complicated iteration constructs. In
  943.         almost every circumstance, a ready-made iteration construct or
  944.         recursive implementation is more appropriate.
  945.  
  946.       - Don't use LET* where LET will do. Don't use LABELS where FLET
  947.         will do. Don't use DO* where DO will do.
  948.  
  949.       - Don't use DO where DOTIMES or DOLIST will do.
  950.  
  951.       - If you like using MAPCAR instead of DO/DOLIST, use MAPC when
  952.         no result is needed -- it's more efficient, since it doesn't
  953.         cons up a list. If a single cumulative value is required, use
  954.         REDUCE. If you are seeking a particular element, use FIND,
  955.         POSITION, or MEMBER.
  956.  
  957.       - If using REMOVE and DELETE to filter a sequence, don't use the
  958.         :test-not keyword or the REMOVE-IF-NOT or DELETE-IF-NOT functions.
  959.         Use COMPLEMENT to complement the predicate and the REMOVE-IF
  960.         or DELETE-IF functions instead.
  961.  
  962.       - Use complex numbers to represent points in a plane.
  963.  
  964.       - Don't use lists where vectors are more appropriate. Accessing the
  965.         nth element of a vector is faster than finding the nth element
  966.         of a list, since the latter requires pointer chasing while the
  967.         former requires simple addition. Vectors also take up less space
  968.         than lists. Use adjustable vectors with fill-pointers to
  969.         implement a stack, instead of a list -- using a list continually
  970.         conses and then throws away the conses.
  971.  
  972.       - When adding an entry to an association list, use ACONS, not
  973.         two calls to CONS. This makes it clear that you're using an alist.
  974.  
  975.       - If your association list has more than about 10 entries in it,
  976.         consider using a hash table. Hash tables are often more efficient.
  977.  
  978.       - When you don't need the full power of CLOS, consider using
  979.         structures instead. They are often faster, take up less space, and
  980.         easier to use.
  981.  
  982.       - Use PRINT-UNREADABLE-OBJECT when writing a print-function.
  983.  
  984.       - Use WITH-OPEN-FILE instead of OPEN and CLOSE.
  985.  
  986.       - When a HANDLER-CASE clause is executed, the stack has already
  987.         unwound, so dynamic bindings that existed when the error
  988.         occured may no longer exist when the handler is run. Use
  989.         HANDLER-BIND if you need this. 
  990.  
  991.       - When using CASE and TYPECASE forms, if you intend for the form
  992.         to return NIL when all cases fail, include an explicit OTHERWISE
  993.         clause. If it would be an error to return NIL when all cases
  994.         fail, use ECASE, CCASE, ETYPECASE or CTYPECASE instead.
  995.  
  996.       - Use local variables in preference to global variables whenever
  997.         possible. Do not use global variables in lieu of parameter passing.
  998.         Global variables can be used in the following circumstances:
  999.           *  When one function needs to affect the operation of
  1000.              another, but the second function isn't called by the first.
  1001.              (For example, *load-pathname* and *break-on-warnings*.)
  1002.           *  When a called function needs to affect the current or future
  1003.              operation of the caller, but it doesn't make sense to accomplish
  1004.              this by returning multiple values.
  1005.           *  To provide hooks into the mechanisms of the program.
  1006.              (For example, *evalhook*, *, /, and +.)
  1007.           *  Parameters which, when their value is changed, represent a
  1008.              major change to the program.
  1009.              (For example, *print-level* and *print-readably*.)
  1010.           *  For state that persists between invocations of the program.
  1011.              Also, for state which is used by more than one major program.
  1012.              (For example, *package*, *readtable*, *gensym-counter*.)
  1013.           *  To provide convenient information to the user.
  1014.              (For example, *version* and *features*.)
  1015.           *  To provide customizable defaults. 
  1016.              (For example, *default-pathname-defaults*.)
  1017.           *  When a value affects major portions of a program, and passing
  1018.              this value around would be extremely awkward. (The example
  1019.              here is output and input streams for a program. Even when
  1020.              the program passes the stream around as an argument, if you
  1021.              want to redirect all output from the program to a different
  1022.              stream, it is much easier to just rebind the global variable.)
  1023.  
  1024.       - Beginning students, especially ones accustomed to programming
  1025.     in C, Pascal, or Fortran, tend to use global variables to hold or pass
  1026.     information in their programs. This style is considered ugly by
  1027.     experienced Lisp programmers. Although assignment statements can't
  1028.     always be avoided in production code, good programmers take advantage
  1029.     of Lisp's functional programming style before resorting to SETF and
  1030.     SETQ. For example, they will nest function calls instead of using a
  1031.     temporary variable and use the stack to pass multiple values. When
  1032.     first learning to program in Lisp, try to avoid SETF/SETQ and their
  1033.     cousins as much as possible. And if a temporary variable is necessary,
  1034.     bind it to its first value in a LET statement, instead of letting it
  1035.     become a global variable by default. (If you see lots of compiler
  1036.     warnings about declaring variables to be special, you're probably
  1037.     making this mistake. If you intend a variable to be global, it should
  1038.     be defined with a DEFVAR or DEFPARAMETER statement, not left to the
  1039.     compiler to fix.)
  1040.  
  1041.    Correctness and efficiency issues:
  1042.  
  1043.       - In CLtL2, IN-PACKAGE does not evaluate its argument. Use defpackage
  1044.         to define a package and declare the external (exported)
  1045.         symbols from the package. 
  1046.  
  1047.       - The ARRAY-TOTAL-SIZE-LIMIT may be as small as 1024, and the
  1048.         CALL-ARGUMENTS-LIMIT may be as small as 50. 
  1049.  
  1050.       - Novices often mistakenly quote the conditions of a CASE form.
  1051.         For example, (case x ('a 3) ..) is incorrect. It would return
  1052.         3 if x were the symbol QUOTE. Use (case x (a 3) ..) instead.
  1053.  
  1054.       - Avoid using APPLY to flatten lists. (apply #'append list-of-lists)
  1055.         is compiled into a function call, and can run into problems with
  1056.         the CALL-ARGUMENTS-LIMIT. Use REDUCE or MAPCAR instead:
  1057.            (reduce #'append list-of-lists :from-end t)
  1058.            (mapcan #'copy-list list-of-lists)
  1059.         The second will often be more efficient (see note below about choosing
  1060.         the right algorithm). Beware of calls like (apply f (mapcar ..)).
  1061.  
  1062.       - NTH must cdr down the list to reach the elements you are
  1063.         interested in. If you don't need the structural flexibility of
  1064.         lists, try using vectors and the ELT function instead.
  1065.  
  1066.       - CASE statements can be vectorized if the keys are consecutive
  1067.         numbers. Such CASE statements can still have OTHERWISE clauses.
  1068.         To take advantage of this without losing readability, use #. with 
  1069.         symbolic constants:
  1070.  
  1071.             (eval-when (compile load eval)
  1072.                (defconstant RED 1)
  1073.                (defconstant GREEN 2)
  1074.                (defconstant BLUE 3))
  1075.  
  1076.             (case color
  1077.               (#.RED   ...)
  1078.               (#.GREEN ...)
  1079.               (#.BLUE  ...)
  1080.               ...)
  1081.  
  1082.       - Don't use quoted constants where you might later destructively
  1083.         modify them. For example, instead of writing '(c d) in
  1084.            (defun foo ()
  1085.              (let ((var '(c d)))
  1086.                ..))
  1087.         write (list 'c 'd) instead. Using a quote here can lead to
  1088.         unexpected results later. If you later destructively modify the 
  1089.         value of var, this is self-modifying code! Some Lisp compilers
  1090.         will complain about this, since they like to make constants
  1091.         read-only. Modifying constants has undefined results in ANSI CL.
  1092.         See also the answer to question [3-13].
  1093.  
  1094.         Similarly, beware of shared list structure arising from the use
  1095.         of backquote. Any sublist in a backquoted expression that doesn't
  1096.         contain any commas can share with the original source structure.
  1097.  
  1098.       - Don't proclaim unsafe optimizations, such as
  1099.            (proclaim '(optimize (safety 0) (speed 3) (space 1))) 
  1100.         since this yields a global effect. Instead, add the
  1101.         optimizations as local declarations to small pieces of
  1102.         well-tested, performance-critical code:
  1103.            (defun well-tested-function ()
  1104.               (declare (optimize (safety 0) (speed 3) (space 1)))
  1105.              ..)
  1106.         Such optimizations can remove run-time type-checking; type-checking
  1107.         is necessary unless you've very carefully checked your code
  1108.         and added all the appropriate type declarations.
  1109.  
  1110.       - Some programmers feel that you shouldn't add declarations to
  1111.         code until it is fully debugged, because incorrect
  1112.         declarations can be an annoying source of errors. They recommend
  1113.         using CHECK-TYPE liberally instead while you are developing the code.
  1114.         On the other hand, if you add declarations to tell the
  1115.         compiler what you think your code is doing, the compiler can
  1116.         then tell you when your assumptions are incorrect.
  1117.         Declarations also make it easier for another programmer to read
  1118.         your code. 
  1119.  
  1120.       - Declaring the type of variables to be FIXNUM does not
  1121.         necessarily mean that the results of arithmetic involving the 
  1122.         fixnums will be a fixnum; it could be a BIGNUM. For example,
  1123.            (declare (type fixnum x y))
  1124.            (setq z (+ (* x x) (* y y)))
  1125.         could result in z being a BIGNUM. If you know the limits of your
  1126.         numbers, use a declaration like
  1127.            (declare (type (integer 0 100) x y))
  1128.         instead, since most compilers can then do the appropriate type
  1129.         inference, leading to much faster code.
  1130.  
  1131.       - Don't change the compiler optimization with an OPTIMIZE
  1132.         proclamation or declaration until the code is fully debugged
  1133.         and profiled.  When first writing code you should say 
  1134.         (declare (optimize (safety 3))) regardless of the speed setting.
  1135.  
  1136.       - Depending on the optimization level of the compiler, type
  1137.         declarations are interpreted either as (1) a guarantee from
  1138.         you that the variable is always bound to values of that type,
  1139.         or (2) a desire that the compiler check that the variable is
  1140.         always bound to values of that type. Use CHECK-TYPE if (2) is
  1141.         your intention.
  1142.  
  1143.       - If you get warnings about unused variables, add IGNORE
  1144.         declarations if appropriate or fix the problem. Letting such
  1145.         warnings stand is a sloppy coding practice.
  1146.  
  1147.    To produce efficient code,
  1148.  
  1149.       - choose the right algorithm. For example, consider seven possible
  1150.         implementations of COPY-LIST:
  1151.  
  1152.            (defun copy-list (list)
  1153.              (let ((result nil))
  1154.                (dolist (item list result)
  1155.                  (setf result (append result (list item))))))
  1156.  
  1157.            (defun copy-list (list)
  1158.              (let ((result nil))
  1159.                (dolist (item list (nreverse result))
  1160.                  (push item result))))
  1161.  
  1162.            (defun copy-list (list)
  1163.              (mapcar #'identity list))
  1164.  
  1165.            (defun copy-list (list)
  1166.              (let ((result (make-list (length list))))
  1167.                (do ((original list (cdr original))
  1168.                     (new result (cdr new)))
  1169.                    ((null original) result)
  1170.                  (setf (car new) (car original)))))
  1171.  
  1172.            (defun copy-list (list)
  1173.              (when list
  1174.                (let* ((result (list (car list)))
  1175.                       (tail-ptr result))
  1176.                  (dolist (item (cdr list) result)
  1177.                    (setf (cdr tail-ptr) (list item))
  1178.                    (setf tail-ptr (cdr tail-ptr))))))
  1179.         
  1180.             (defun copy-list (list)
  1181.               (loop for item in list collect item))
  1182.  
  1183.             (defun copy-list (list)
  1184.               (if (consp list) 
  1185.                   (cons (car list)
  1186.                         (copy-list (cdr list)))
  1187.                   list))
  1188.  
  1189.         The first uses APPEND to tack the elements onto the end of the list.
  1190.         Since APPEND must traverse the entire partial list at each step, this
  1191.         yields a quadratic running time for the algorithm.  The second
  1192.         implementation improves on this by iterating down the list twice; once
  1193.         to build up the list in reverse order, and the second time to reverse
  1194.         it. The efficiency of the third depends on the Lisp implementation,
  1195.         but it is usually similar to the second, as is the fourth.  The fifth
  1196.         algorithm, however, iterates down the list only once. It avoids the
  1197.         extra work by keeping a pointer (reference) to the last cons of the 
  1198.         list and RPLACDing onto the end of that. Use of the fifth algorithm 
  1199.         may yield a speedup. Note that this contradicts the earlier dictum to
  1200.         avoid destructive functions. To make more efficient code one might
  1201.         selectively introduce destructive operations in critical sections of
  1202.         code. Nevertheless, the fifth implementation may be less efficient in
  1203.         Lisps with cdr-coding, since it is more expensive to RPLACD cdr-coded
  1204.         lists. Depending on the implementation of nreverse, however,
  1205.         the fifth and second implementations may be doing the same
  1206.         amount of work. The sixth example uses the Loop macro, which usually
  1207.         expands into code similar to the third. The seventh example copies
  1208.         dotted lists, and runs in linear time, but isn't tail-recursive. 
  1209.  
  1210.       - use type declarations liberally in time-critical code, but
  1211.         only if you are a seasoned Lisp programmer. Appropriate type
  1212.         declarations help the compiler generate more specific and
  1213.         optimized code. It also lets the reader know what assumptions
  1214.         were made. For example, if you only use fixnum arithmetic,
  1215.         adding declarations can lead to a significant speedup. If you
  1216.         are a novice Lisp programmer, you should use type declarations
  1217.         sparingly, as there may be no checking to see if the
  1218.         declarations are correct, and optimized code can be harder to
  1219.         debug. Wrong declarations can lead to errors in otherwise
  1220.         correct code, and can limit the reuse of code in other
  1221.         contexts. Depending on the Lisp compiler, it may also 
  1222.         be necessary to declare the type of results using THE, since
  1223.         some compilers don't deduce the result type from the inputs.
  1224.  
  1225.       - check the code produced by the compiler by using the
  1226.         disassemble function
  1227.  
  1228. ----------------------------------------------------------------
  1229. Subject: [1-4] Where can I learn about implementing Lisp interpreters 
  1230.                and compilers?
  1231.  
  1232. Books about Lisp implementation include:
  1233.  
  1234.    1. John Allen
  1235.       "Anatomy of Lisp"
  1236.       McGraw-Hill, 1978. 446 pages. ISBN 0-07-001115-X
  1237.  
  1238.    2. Samuel Kamin
  1239.       "Programming Languages, An Interpreter-Based Approach"
  1240.       Addison-Wesley, Reading, Mass., 1990. ISBN 0-201-06824-9
  1241.            Includes sources to several interpreters for Lisp-like
  1242.            languages, and a pointer to sources via anonymous ftp.
  1243.  
  1244.    3. Sharam Hekmatpour
  1245.       "Lisp: A Portable Implementation"
  1246.       Prentice Hall, 1985. ISBN 0-13-537490-X.
  1247.            Describes a portable implementation of a small dynamic
  1248.            Lisp interpreter (including C source code). 
  1249.  
  1250.    4. Peter Henderson
  1251.       "Functional Programming: Application and Implementation"
  1252.       Prentice-Hall (Englewood Cliffs, NJ), 1980. 355 pages.
  1253.  
  1254.    5. Peter M. Kogge
  1255.       "The Architecture of Symbolic Computers"
  1256.       McGraw-Hill, 1991. ISBN 0-07-035596-7.
  1257.            Includes sections on memory management, the SECD and
  1258.            Warren Abstract Machines, and overviews of the various
  1259.            Lisp Machine architectures.
  1260.    
  1261.    6. Daniel P. Friedman, Mitchell Wand, and Christopher T. Haynes
  1262.       "Essentials of Programming Languages"
  1263.       MIT Press, 1992, 536 pages. ISBN 0-262-06145-7.
  1264.            Teaches fundamental concepts of programming language
  1265.            design by using small interpreters as examples. Covers
  1266.            most of the features of Scheme. Includes a discussion
  1267.            of parameter passing techniques, object oriented languages,
  1268.            and techniques for transforming interpreters to allow
  1269.            their implementation in terms of any low-level language.
  1270.            Also discusses scanners, parsers, and the derivation of
  1271.            a compiler and virtual machine from an interpreter.
  1272.            Source files available by anonymous ftp from cs.indiana.edu
  1273.            in the directory /pub/eopl (129.79.254.191).
  1274.  
  1275.    7. Peter Lee, editor, "Topics in Advanced Language Implementation",
  1276.       The MIT Press, Cambridge, Mass., 1991.
  1277.            Articles relevant to the implementation of functional
  1278.            programming languages.
  1279.  
  1280.    8. Also see the proceedings of the biannual ACM Lisp and Functional
  1281.       Programming conferences, the implementation notes for CMU Common Lisp,
  1282.       Norvig's book, and SICP (Abelson & Sussman).
  1283.  
  1284. ----------------------------------------------------------------
  1285. Subject: [1-5]  What does CLOS, PCL, X3J13, CAR, CDR, ... mean? 
  1286.  
  1287. Glossary of acronyms:
  1288.    CAR             Originally meant "Contents of Address portion of Register",
  1289.                    which is what CAR actually did on the IBM 704.
  1290.    CDR             Originally meant "Contents of Decrement portion of 
  1291.                    Register", which is what CDR actually did
  1292.                    on the IBM 704. Pronounced "Cudder".
  1293.    LISP            Originally from "LISt Processing"
  1294.    GUI             Graphical User Interface
  1295.    CLOS            Common Lisp Object System. The object oriented
  1296.                    programming standard for Common Lisp. Based on
  1297.                    Symbolics FLAVORS and Xerox LOOPS, among others.
  1298.                    Pronounced either as "See-Loss" or "Closs". See also PCL.
  1299.    PCL             Portable Common Loops. A portable CLOS implementation.
  1300.                    Available by anonymous ftp from parcftp.xerox.com:pcl/.
  1301.    LOOPS           Lisp Object Oriented Programming System. A predecessor
  1302.                    to CLOS on Xerox Lisp machines.
  1303.    X3J13           Subcommittee of the ANSI committee X3 which is
  1304.                    working on the ANSI Standardization of Common Lisp.
  1305.    ANSI            American National Standards Institute
  1306.    CL              Common Lisp
  1307.    SC22/WG16       The full name is ISO/IEC JTC 1/SC 22/WG 16. It stands
  1308.                    for International Organization for
  1309.                    Standardization/International Electronics(?)  
  1310.                    Congress(?) Joint Technical Committee 1, Subcommittee 22,
  1311.                    Working Group 16.  This long-winded name is the ISO
  1312.                    working group working on an international Lisp standard,
  1313.                    (i.e., the ISO analogue to X3J13).
  1314.    CLtL1           First edition of Guy Steele's book, 
  1315.                    "Common Lisp the Language". 
  1316.    CLtL2           Second edition of Guy Steele's book,
  1317.                    "Common Lisp the Language". 
  1318.  
  1319. ----------------------------------------------------------------
  1320. Subject: [1-6] Lisp Job Postings
  1321.  
  1322. The LISP-JOBS mailing list exists to help programmers find Lisp
  1323. programming positions, and to help companies with Lisp programming
  1324. positions find capable Lisp programmers. (Lisp here means Lisp-like
  1325. languages, including Scheme.)
  1326.  
  1327. Material appropriate for the list includes Lisp job announcements and
  1328. resumes from Lisp programmers (which should be sent only once) should
  1329. be sent to lisp-jobs@cis.ohio-state.edu.  Administrative requests (e.g., to be
  1330. added to the list) should be sent to lisp-jobs-request@cis.ohio-state.edu.
  1331.  
  1332. ----------------------------------------------------------------
  1333.  
  1334. ;;; *EOF*
  1335.